package game.domain;

import javax.vecmath.Point2d;
import java.awt.*;

public class PolygonGenerator {
	private static final double TWO_PI = Math.PI * 2.0;

	public Polygon generate(Point2d position, double heading, int numberOfSides, int size) {
		// TODO could optimise this so that it keeps the polygon without position added and only adds position when needed.
		final int numberOfPoints = numberOfSides;
		final int xCoordinates[] = new int[numberOfPoints];
		final int yCoordinates[] = new int[numberOfPoints];
		for (int i = 0; i < numberOfPoints; i++) {
			double angle = heading + TWO_PI * i / numberOfPoints;
			xCoordinates[i] = (int) (size * Math.cos(angle) + position.x);
			yCoordinates[i] = (int) (size * Math.sin(angle) + position.y);
		}
		return new Polygon(xCoordinates, yCoordinates, numberOfPoints);
	}
}
